#本文件用于为myNet下的组织生成加密材料

function createOrg1() {
  infoln "Enrolling the CA admin"
  mkdir -p organizations/peerOrganizations/org1.project.com/

  export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/peerOrganizations/org1.project.com/

  set -x
  #7054是org1的ca服务器端口
  fabric-ca-client enroll -u https://admin:123456@localhost:7054 --caname ca-org1 --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem"
  { set +x; } 2>/dev/null

  echo 'NodeOUs:
  Enable: true
  ClientOUIdentifier:
    Certificate: cacerts/localhost-7054-ca-org1.pem
    OrganizationalUnitIdentifier: client
  PeerOUIdentifier:
    Certificate: cacerts/localhost-7054-ca-org1.pem
    OrganizationalUnitIdentifier: peer
  AdminOUIdentifier:
    Certificate: cacerts/localhost-7054-ca-org1.pem
    OrganizationalUnitIdentifier: admin
  OrdererOUIdentifier:
    Certificate: cacerts/localhost-7054-ca-org1.pem
    OrganizationalUnitIdentifier: orderer' > "${PWD}/organizations/peerOrganizations/org1.project.com/msp/config.yaml"

  #将org1的ca证书复制到/msp/tlscacerts目录下
  mkdir -p "${PWD}/organizations/peerOrganizations/org1.project.com/msp/tlscacerts"
  cp "${PWD}/organizations/fabric-ca/org1/ca-cert.pem" "${PWD}/organizations/peerOrganizations/org1.project.com/msp/tlscacerts/ca.crt"

  #将org1的ca证书复制到/tlsca目录下，以便客户端连接
  mkdir -p "${PWD}/organizations/peerOrganizations/org1.project.com/tlsca"
  cp "${PWD}/organizations/fabric-ca/org1/ca-cert.pem" "${PWD}/organizations/peerOrganizations/org1.project.com/tlsca/tlsca.org1.project.com-cert.pem"

  #将org1的ca证书复制到ca目录下
  mkdir -p "${PWD}/organizations/peerOrganizations/org1.project.com/ca"
  cp "${PWD}/organizations/fabric-ca/org1/ca-cert.pem" "${PWD}/organizations/peerOrganizations/org1.project.com/ca/ca.org1.project.com-cert.pem"

  #注册peer0.org1
  infoln "Registering peer0.org1"
  set -x
  fabric-ca-client register --caname ca-org1 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem"
  { set +x; } 2>/dev/null

  #注册peer1.org1
  infoln "Registering peer1.org1"
  set -x
  fabric-ca-client register --caname ca-org1 --id.name peer1 --id.secret peer1pw --id.type peer --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem"
  { set +x; } 2>/dev/null

  #注册user1
  infoln "Registering user1"
  set -x
  fabric-ca-client register --caname ca-org1 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem"
  { set +x; } 2>/dev/null

  #注册org1dmin
  infoln "Registering the org admin"
  set -x
  fabric-ca-client register --caname ca-org1 --id.name org1admin --id.secret org1adminpw --id.type admin --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem"
  { set +x; } 2>/dev/null

  ##
  #生成peer0的msp
  infoln "Generating the peer0.org1 msp"
  set -x
  fabric-ca-client enroll -u https://peer0:peer0pw@localhost:7054 --caname ca-org1 -M "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer0.org1.project.com/msp" --csr.hosts peer0.org1.project.com --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/peerOrganizations/org1.project.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer0.org1.project.com/msp/config.yaml"

  #生成peer0-tls证书
  infoln "Generating the peer0.org1-tls certificates"
  set -x
  fabric-ca-client enroll -u https://peer0:peer0pw@localhost:7054 --caname ca-org1 -M "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer0.org1.project.com/tls" --enrollment.profile tls --csr.hosts peer0.org1.project.com --csr.hosts localhost --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem"
  { set +x; } 2>/dev/null

  #将peer0-tls证书移动到规范化的目录下
  cp "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer0.org1.project.com/tls/tlscacerts/"* "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer0.org1.project.com/tls/ca.crt"
  cp "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer0.org1.project.com/tls/signcerts/"* "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer0.org1.project.com/tls/server.crt"
  cp "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer0.org1.project.com/tls/keystore/"* "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer0.org1.project.com/tls/server.key"
  ##

  ##
  #生成peer1的msp
  infoln "Generating the peer1.org1 msp"
  set -x
  fabric-ca-client enroll -u https://peer1:peer1pw@localhost:7054 --caname ca-org1 -M "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer1.org1.project.com/msp" --csr.hosts peer1.org1.project.com --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/peerOrganizations/org1.project.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer1.org1.project.com/msp/config.yaml"

  #生成peer1-tls证书
  infoln "Generating the peer1.org1-tls certificates"
  set -x
  fabric-ca-client enroll -u https://peer1:peer1pw@localhost:7054 --caname ca-org1 -M "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer1.org1.project.com/tls" --enrollment.profile tls --csr.hosts peer1.org1.project.com --csr.hosts localhost --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem"
  { set +x; } 2>/dev/null

  #将peer1-tls证书移动到规范化的目录下
  cp "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer1.org1.project.com/tls/tlscacerts/"* "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer1.org1.project.com/tls/ca.crt"
  cp "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer1.org1.project.com/tls/signcerts/"* "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer1.org1.project.com/tls/server.crt"
  cp "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer1.org1.project.com/tls/keystore/"* "${PWD}/organizations/peerOrganizations/org1.project.com/peers/peer1.org1.project.com/tls/server.key"
  ##

  #生成user1的msp
  infoln "Generating the user1 msp"
  set -x
  fabric-ca-client enroll -u https://user1:user1pw@localhost:7054 --caname ca-org1 -M "${PWD}/organizations/peerOrganizations/org1.project.com/users/User1@org1.project.com/msp" --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/peerOrganizations/org1.project.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org1.project.com/users/User1@org1.project.com/msp/config.yaml"

  #生成org1dmin的msp
  infoln "Generating the org1 admin msp"
  set -x
  fabric-ca-client enroll -u https://org1admin:org1adminpw@localhost:7054 --caname ca-org1 -M "${PWD}/organizations/peerOrganizations/org1.project.com/users/Admin@org1.project.com/msp" --tls.certfiles "${PWD}/organizations/fabric-ca/org1/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/peerOrganizations/org1.project.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org1.project.com/users/Admin@org1.project.com/msp/config.yaml"
}

function createOrg2() {
  infoln "Enrolling the CA admin"
  mkdir -p organizations/peerOrganizations/org2.project.com/

  export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/peerOrganizations/org2.project.com/

  set -x
  #9054是org2的ca服务器端口
  fabric-ca-client enroll -u https://admin:123456@localhost:9054 --caname ca-org2 --tls.certfiles "${PWD}/organizations/fabric-ca/org2/ca-cert.pem"
  { set +x; } 2>/dev/null

  echo 'NodeOUs:
  Enable: true
  ClientOUIdentifier:
    Certificate: cacerts/localhost-9054-ca-org2.pem
    OrganizationalUnitIdentifier: client
  PeerOUIdentifier:
    Certificate: cacerts/localhost-9054-ca-org2.pem
    OrganizationalUnitIdentifier: peer
  AdminOUIdentifier:
    Certificate: cacerts/localhost-9054-ca-org2.pem
    OrganizationalUnitIdentifier: admin
  OrdererOUIdentifier:
    Certificate: cacerts/localhost-9054-ca-org2.pem
    OrganizationalUnitIdentifier: orderer' > "${PWD}/organizations/peerOrganizations/org2.project.com/msp/config.yaml"

  #将org2的ca证书复制到/msp/tlscacerts目录下
  mkdir -p "${PWD}/organizations/peerOrganizations/org2.project.com/msp/tlscacerts"
  cp "${PWD}/organizations/fabric-ca/org2/ca-cert.pem" "${PWD}/organizations/peerOrganizations/org2.project.com/msp/tlscacerts/ca.crt"

  #将org2的ca证书复制到/tlsca目录下，以便客户端连接
  mkdir -p "${PWD}/organizations/peerOrganizations/org2.project.com/tlsca"
  cp "${PWD}/organizations/fabric-ca/org2/ca-cert.pem" "${PWD}/organizations/peerOrganizations/org2.project.com/tlsca/tlsca.org2.project.com-cert.pem"

  #将org2的ca证书复制到ca目录下
  mkdir -p "${PWD}/organizations/peerOrganizations/org2.project.com/ca"
  cp "${PWD}/organizations/fabric-ca/org2/ca-cert.pem" "${PWD}/organizations/peerOrganizations/org2.project.com/ca/ca.org2.project.com-cert.pem"

  #注册peer0.org2
  infoln "Registering peer0.org2"
  set -x
  fabric-ca-client register --caname ca-org2 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles "${PWD}/organizations/fabric-ca/org2/ca-cert.pem"
  { set +x; } 2>/dev/null

  #注册peer1.org2
  infoln "Registering peer1.org2"
  set -x
  fabric-ca-client register --caname ca-org2 --id.name peer1 --id.secret peer1pw --id.type peer --tls.certfiles "${PWD}/organizations/fabric-ca/org2/ca-cert.pem"
  { set +x; } 2>/dev/null

  #注册user1
  infoln "Registering user1"
  set -x
  fabric-ca-client register --caname ca-org2 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles "${PWD}/organizations/fabric-ca/org2/ca-cert.pem"
  { set +x; } 2>/dev/null

  #注册org2Admin
  infoln "Registering the org 2"
  set -x
  fabric-ca-client register --caname ca-org2 --id.name org2admin --id.secret org2adminpw --id.type admin --tls.certfiles "${PWD}/organizations/fabric-ca/org2/ca-cert.pem"
  { set +x; } 2>/dev/null

  ##
  #生成peer0的msp
  infoln "Generating the peer0.org2 msp"
  set -x
  fabric-ca-client enroll -u https://peer0:peer0pw@localhost:9054 --caname ca-org2 -M "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer0.org2.project.com/msp" --csr.hosts peer0.org2.project.com --tls.certfiles "${PWD}/organizations/fabric-ca/org2/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/peerOrganizations/org2.project.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer0.org2.project.com/msp/config.yaml"

  #生成peer0-tls证书
  infoln "Generating the peer0.org2-tls certificates"
  set -x
  fabric-ca-client enroll -u https://peer0:peer0pw@localhost:9054 --caname ca-org2 -M "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer0.org2.project.com/tls" --enrollment.profile tls --csr.hosts peer0.org2.project.com --csr.hosts localhost --tls.certfiles "${PWD}/organizations/fabric-ca/org2/ca-cert.pem"
  { set +x; } 2>/dev/null

  #将peer0-tls证书移动到规范化的目录下
  cp "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer0.org2.project.com/tls/tlscacerts/"* "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer0.org2.project.com/tls/ca.crt"
  cp "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer0.org2.project.com/tls/signcerts/"* "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer0.org2.project.com/tls/server.crt"
  cp "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer0.org2.project.com/tls/keystore/"* "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer0.org2.project.com/tls/server.key"
  ##

  ##
  #生成peer1的msp
  infoln "Generating the peer1.org2 msp"
  set -x
  fabric-ca-client enroll -u https://peer1:peer1pw@localhost:9054 --caname ca-org2 -M "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer1.org2.project.com/msp" --csr.hosts peer1.org2.project.com --tls.certfiles "${PWD}/organizations/fabric-ca/org2/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/peerOrganizations/org2.project.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer1.org2.project.com/msp/config.yaml"

  #生成peer1-tls证书
  infoln "Generating the peer1.org2-tls certificates"
  set -x
  fabric-ca-client enroll -u https://peer1:peer1pw@localhost:9054 --caname ca-org2 -M "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer1.org2.project.com/tls" --enrollment.profile tls --csr.hosts peer1.org2.project.com --csr.hosts localhost --tls.certfiles "${PWD}/organizations/fabric-ca/org2/ca-cert.pem"
  { set +x; } 2>/dev/null

  #将peer1-tls证书移动到规范化的目录下
  cp "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer1.org2.project.com/tls/tlscacerts/"* "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer1.org2.project.com/tls/ca.crt"
  cp "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer1.org2.project.com/tls/signcerts/"* "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer1.org2.project.com/tls/server.crt"
  cp "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer1.org2.project.com/tls/keystore/"* "${PWD}/organizations/peerOrganizations/org2.project.com/peers/peer1.org2.project.com/tls/server.key"
  ##

  #生成user1的msp
  infoln "Generating the user1 msp"
  set -x
  fabric-ca-client enroll -u https://user1:user1pw@localhost:9054 --caname ca-org2 -M "${PWD}/organizations/peerOrganizations/org2.project.com/users/User1@org2.project.com/msp" --tls.certfiles "${PWD}/organizations/fabric-ca/org2/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/peerOrganizations/org2.project.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org2.project.com/users/User1@org2.project.com/msp/config.yaml"

  #生成org2Admin的msp
  infoln "Generating the org2 admin msp"
  set -x
  fabric-ca-client enroll -u https://org2admin:org2adminpw@localhost:9054 --caname ca-org2 -M "${PWD}/organizations/peerOrganizations/org2.project.com/users/Admin@org2.project.com/msp" --tls.certfiles "${PWD}/organizations/fabric-ca/org2/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/peerOrganizations/org2.project.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org2.project.com/users/Admin@org2.project.com/msp/config.yaml"
}

function createOrg3() {
  infoln "Enrolling the CA admin"
  mkdir -p organizations/peerOrganizations/org3.project.com/

  export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/peerOrganizations/org3.project.com/

  set -x
  #8054是org3的ca服务器端口
  fabric-ca-client enroll -u https://admin:123456@localhost:8054 --caname ca-org3 --tls.certfiles "${PWD}/organizations/fabric-ca/org3/ca-cert.pem"
  { set +x; } 2>/dev/null

  echo 'NodeOUs:
  Enable: true
  ClientOUIdentifier:
    Certificate: cacerts/localhost-8054-ca-org3.pem
    OrganizationalUnitIdentifier: client
  PeerOUIdentifier:
    Certificate: cacerts/localhost-8054-ca-org3.pem
    OrganizationalUnitIdentifier: peer
  AdminOUIdentifier:
    Certificate: cacerts/localhost-8054-ca-org3.pem
    OrganizationalUnitIdentifier: admin
  OrdererOUIdentifier:
    Certificate: cacerts/localhost-8054-ca-org3.pem
    OrganizationalUnitIdentifier: orderer' > "${PWD}/organizations/peerOrganizations/org3.project.com/msp/config.yaml"

  #将org3的ca证书复制到/msp/tlscacerts目录下
  mkdir -p "${PWD}/organizations/peerOrganizations/org3.project.com/msp/tlscacerts"
  cp "${PWD}/organizations/fabric-ca/org3/ca-cert.pem" "${PWD}/organizations/peerOrganizations/org3.project.com/msp/tlscacerts/ca.crt"

  #将org3的ca证书复制到/tlsca目录下，以便客户端连接
  mkdir -p "${PWD}/organizations/peerOrganizations/org3.project.com/tlsca"
  cp "${PWD}/organizations/fabric-ca/org3/ca-cert.pem" "${PWD}/organizations/peerOrganizations/org3.project.com/tlsca/tlsca.org3.project.com-cert.pem"

  #将org3的ca证书复制到ca目录下
  mkdir -p "${PWD}/organizations/peerOrganizations/org3.project.com/ca"
  cp "${PWD}/organizations/fabric-ca/org3/ca-cert.pem" "${PWD}/organizations/peerOrganizations/org3.project.com/ca/ca.org3.project.com-cert.pem"

  #注册peer0.org3
  infoln "Registering peer0.org3"
  set -x
  fabric-ca-client register --caname ca-org3 --id.name peer0 --id.secret peer0pw --id.type peer --tls.certfiles "${PWD}/organizations/fabric-ca/org3/ca-cert.pem"
  { set +x; } 2>/dev/null

  #注册peer1.org3
  infoln "Registering peer1.org3"
  set -x
  fabric-ca-client register --caname ca-org3 --id.name peer1 --id.secret peer1pw --id.type peer --tls.certfiles "${PWD}/organizations/fabric-ca/org3/ca-cert.pem"
  { set +x; } 2>/dev/null

  #注册user1
  infoln "Registering user1"
  set -x
  fabric-ca-client register --caname ca-org3 --id.name user1 --id.secret user1pw --id.type client --tls.certfiles "${PWD}/organizations/fabric-ca/org3/ca-cert.pem"
  { set +x; } 2>/dev/null

  #注册org3dmin
  infoln "Registering the org admin"
  set -x
  fabric-ca-client register --caname ca-org3 --id.name org3admin --id.secret org3adminpw --id.type admin --tls.certfiles "${PWD}/organizations/fabric-ca/org3/ca-cert.pem"
  { set +x; } 2>/dev/null

  ##
  #生成peer0的msp
  infoln "Generating the peer0.org3 msp"
  set -x
  fabric-ca-client enroll -u https://peer0:peer0pw@localhost:8054 --caname ca-org3 -M "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer0.org3.project.com/msp" --csr.hosts peer0.org3.project.com --tls.certfiles "${PWD}/organizations/fabric-ca/org3/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/peerOrganizations/org3.project.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer0.org3.project.com/msp/config.yaml"

  #生成peer0-tls证书
  infoln "Generating the peer0.org3-tls certificates"
  set -x
  fabric-ca-client enroll -u https://peer0:peer0pw@localhost:8054 --caname ca-org3 -M "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer0.org3.project.com/tls" --enrollment.profile tls --csr.hosts peer0.org3.project.com --csr.hosts localhost --tls.certfiles "${PWD}/organizations/fabric-ca/org3/ca-cert.pem"
  { set +x; } 2>/dev/null

  #将peer0-tls证书移动到规范化的目录下
  cp "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer0.org3.project.com/tls/tlscacerts/"* "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer0.org3.project.com/tls/ca.crt"
  cp "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer0.org3.project.com/tls/signcerts/"* "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer0.org3.project.com/tls/server.crt"
  cp "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer0.org3.project.com/tls/keystore/"* "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer0.org3.project.com/tls/server.key"
  ##

  ##
  #生成peer1的msp
  infoln "Generating the peer1.org3 msp"
  set -x
  fabric-ca-client enroll -u https://peer1:peer1pw@localhost:8054 --caname ca-org3 -M "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer1.org3.project.com/msp" --csr.hosts peer1.org3.project.com --tls.certfiles "${PWD}/organizations/fabric-ca/org3/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/peerOrganizations/org3.project.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer1.org3.project.com/msp/config.yaml"

  #生成peer1-tls证书
  infoln "Generating the peer1.org3-tls certificates"
  set -x
  fabric-ca-client enroll -u https://peer1:peer1pw@localhost:8054 --caname ca-org3 -M "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer1.org3.project.com/tls" --enrollment.profile tls --csr.hosts peer1.org3.project.com --csr.hosts localhost --tls.certfiles "${PWD}/organizations/fabric-ca/org3/ca-cert.pem"
  { set +x; } 2>/dev/null

  #将peer1-tls证书移动到规范化的目录下
  cp "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer1.org3.project.com/tls/tlscacerts/"* "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer1.org3.project.com/tls/ca.crt"
  cp "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer1.org3.project.com/tls/signcerts/"* "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer1.org3.project.com/tls/server.crt"
  cp "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer1.org3.project.com/tls/keystore/"* "${PWD}/organizations/peerOrganizations/org3.project.com/peers/peer1.org3.project.com/tls/server.key"
  ##

  #生成user1的msp
  infoln "Generating the user1 msp"
  set -x
  fabric-ca-client enroll -u https://user1:user1pw@localhost:8054 --caname ca-org3 -M "${PWD}/organizations/peerOrganizations/org3.project.com/users/User1@org3.project.com/msp" --tls.certfiles "${PWD}/organizations/fabric-ca/org3/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/peerOrganizations/org3.project.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org3.project.com/users/User1@org3.project.com/msp/config.yaml"

  #生成org3dmin的msp
  infoln "Generating the org3 admin msp"
  set -x
  fabric-ca-client enroll -u https://org3admin:org3adminpw@localhost:8054 --caname ca-org3 -M "${PWD}/organizations/peerOrganizations/org3.project.com/users/Admin@org3.project.com/msp" --tls.certfiles "${PWD}/organizations/fabric-ca/org3/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/peerOrganizations/org3.project.com/msp/config.yaml" "${PWD}/organizations/peerOrganizations/org3.project.com/users/Admin@org3.project.com/msp/config.yaml"
}

function createOrderer() {
  infoln "Enrolling the CA admin"
  mkdir -p organizations/ordererOrganizations/project.com

  export FABRIC_CA_CLIENT_HOME=${PWD}/organizations/ordererOrganizations/project.com

  set -x
  fabric-ca-client enroll -u https://admin:123456@localhost:10054 --caname ca-orderer --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
  { set +x; } 2>/dev/null

  echo 'NodeOUs:
  Enable: true
  ClientOUIdentifier:
    Certificate: cacerts/localhost-10054-ca-orderer.pem
    OrganizationalUnitIdentifier: client
  PeerOUIdentifier:
    Certificate: cacerts/localhost-10054-ca-orderer.pem
    OrganizationalUnitIdentifier: peer
  AdminOUIdentifier:
    Certificate: cacerts/localhost-10054-ca-orderer.pem
    OrganizationalUnitIdentifier: admin
  OrdererOUIdentifier:
    Certificate: cacerts/localhost-10054-ca-orderer.pem
    OrganizationalUnitIdentifier: orderer' > "${PWD}/organizations/ordererOrganizations/project.com/msp/config.yaml"

  mkdir -p "${PWD}/organizations/ordererOrganizations/project.com/msp/tlscacerts"
  cp "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem" "${PWD}/organizations/ordererOrganizations/project.com/msp/tlscacerts/tlsca.project.com-cert.pem"

  mkdir -p "${PWD}/organizations/ordererOrganizations/project.com/tlsca"
  cp "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem" "${PWD}/organizations/ordererOrganizations/project.com/tlsca/tlsca.project.com-cert.pem"

  #注册orderer节点
  infoln "Registering orderer"
  set -x
  fabric-ca-client register --caname ca-orderer --id.name orderer --id.secret ordererpw --id.type orderer --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
  { set +x; } 2>/dev/null

  #注册orderer管理员身份
  infoln "Registering the orderer admin"
  set -x
  fabric-ca-client register --caname ca-orderer --id.name ordererAdmin --id.secret ordererAdminpw --id.type admin --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
  { set +x; } 2>/dev/null

  #生成orderer的msp
  infoln "Generating the orderer msp"
  set -x
  fabric-ca-client enroll -u https://orderer:ordererpw@localhost:10054 --caname ca-orderer -M "${PWD}/organizations/ordererOrganizations/project.com/orderers/orderer.project.com/msp" --csr.hosts orderer.project.com --csr.hosts localhost --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/ordererOrganizations/project.com/msp/config.yaml" "${PWD}/organizations/ordererOrganizations/project.com/orderers/orderer.project.com/msp/config.yaml"

  #生成orderer的tls证书
  infoln "Generating the orderer-tls certificates"
  set -x
  fabric-ca-client enroll -u https://orderer:ordererpw@localhost:10054 --caname ca-orderer -M "${PWD}/organizations/ordererOrganizations/project.com/orderers/orderer.project.com/tls" --enrollment.profile tls --csr.hosts orderer.project.com --csr.hosts localhost --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
  { set +x; } 2>/dev/null

  #规范化加密材料目录
  cp "${PWD}/organizations/ordererOrganizations/project.com/orderers/orderer.project.com/tls/tlscacerts/"* "${PWD}/organizations/ordererOrganizations/project.com/orderers/orderer.project.com/tls/ca.crt"
  cp "${PWD}/organizations/ordererOrganizations/project.com/orderers/orderer.project.com/tls/signcerts/"* "${PWD}/organizations/ordererOrganizations/project.com/orderers/orderer.project.com/tls/server.crt"
  cp "${PWD}/organizations/ordererOrganizations/project.com/orderers/orderer.project.com/tls/keystore/"* "${PWD}/organizations/ordererOrganizations/project.com/orderers/orderer.project.com/tls/server.key"

  mkdir -p "${PWD}/organizations/ordererOrganizations/project.com/orderers/orderer.project.com/msp/tlscacerts"
  cp "${PWD}/organizations/ordererOrganizations/project.com/orderers/orderer.project.com/tls/tlscacerts/"* "${PWD}/organizations/ordererOrganizations/project.com/orderers/orderer.project.com/msp/tlscacerts/tlsca.project.com-cert.pem"

  #生成ordererAdmin的msp
  infoln "Generating the admin msp"
  set -x
  fabric-ca-client enroll -u https://ordererAdmin:ordererAdminpw@localhost:10054 --caname ca-orderer -M "${PWD}/organizations/ordererOrganizations/project.com/users/Admin@project.com/msp" --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
  { set +x; } 2>/dev/null

  cp "${PWD}/organizations/ordererOrganizations/project.com/msp/config.yaml" "${PWD}/organizations/ordererOrganizations/project.com/users/Admin@project.com/msp/config.yaml"
}
